/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datas;

import beans.Transact;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class TransactObj {

    private connect con;

    public TransactObj() {
        con = new connect();
    }

    public int Transact(Transact tran) {
        try {
            CallableStatement csInsert = con.getConnect().prepareCall("{call DoTransact(?,?,?)}");
            csInsert.setString(1, tran.getAccountNo());
            csInsert.setString(2, tran.getType());
            csInsert.setInt(3, tran.getAmount());
            return csInsert.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AccountObj.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }

    public List List(String AccountNo) {
        List transfers = new ArrayList();
        try {
            CallableStatement csList = con.getConnect().prepareCall("{call ListTransact(?)}");
            csList.setString("AccountNo", AccountNo);
            ResultSet datas = csList.executeQuery();
            while (datas.next()) {
                Transact tran = new Transact();
                tran.setId(Integer.parseInt(datas.getString("id")));
                tran.setAccountNo(datas.getString("AccountNo"));
                tran.setAmount(Integer.parseInt(datas.getString("Amount")));
                tran.setDate(datas.getString("Date"));
                tran.setType(datas.getString("TypeTransact"));
                transfers.add(tran);
            }
            return transfers;
        } catch (SQLException ex) {
            Logger.getLogger(TransactObj.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
